<template>
  <div class="app-container">
    <div class="filter-container">
      <el-select
        v-model="listQuery.status"
        style="width: 150px"
        class="filter-item"
        size="small"
        @change="handleFilter"
      >
        <el-option key="1" label="已启用" :value="'1'" />
        <el-option key="2" label="已停用" :value="'2'" />
        <el-option key label="全部状态" :value="''" />
      </el-select>
      <el-input
        v-model="listQuery.proxy"
        placeholder="请输入渠道进行搜索"
        style="width: 220px;"
        class="filter-item"
        size="small"
        @keyup.enter.native="handleFilter"
      />
      <el-button
       plain size="small"
        v-waves
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
      >搜索</el-button>
      <!-- <el-button
       plain size="small"
        v-waves
        class="filter-item btn"
        type="primary"
        icon="el-icon-refresh"
        @click="handleCancel"
      >重置</el-button> -->
      <br/>
      <el-button
       plain size="small"
        v-waves
        class="filter-item btn"
        type="success"
        @click="handleCreate"
      >新增渠道</el-button>
    </div>

    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <!-- <el-table-column label="序号" align="center" prop="id" width="60" type="index" /> -->
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="hap链接： ">
                <div v-html="get_hap(props.row)"></div>
            </el-form-item>
            <el-form-item label="点击监测链接：">
              <div v-html="get_jiance(props.row)"></div>
            </el-form-item>
            
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="渠道" min-width="50" align="center">
        <template slot-scope="{row}">
          <span>{{ row.username }}</span>
        </template>
      </el-table-column>

      <el-table-column label="总UV" min-width="50" align="center">
        <template slot-scope="{row}">
          <span>{{ row.uv_sum }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总PV" min-width="50" align="center">
        <template slot-scope="{row}">
          <span>{{ row.pv_sum }}</span>
        </template>
      </el-table-column>
      <el-table-column label="渠道状态" min-width="50" align="center">
        <template slot-scope="{row}">
          <el-switch
            v-model="row.status"
            :active-value="'1'"
            :inactive-value="'2'"
            @change="changeProxyStatus(row)"
          />
        </template>
      </el-table-column>
      <el-table-column label="推广渠道" min-width="50" align="center">
        <template slot-scope="{row}">
          <span>{{ tg_option[row.tg] }}</span>
        </template>
      </el-table-column>
      <el-table-column label="包名" min-width="50" align="center">
        <template slot-scope="{row}">
          <span> {{optionPackageName[row.pkg]}}</span>
        </template>
      </el-table-column>
      <el-table-column label="配置" min-width="80" align="left">
        <template slot-scope="{row}">
          <div v-if="row.channel_config">
            <!-- <el-link>书籍id : {{ row.channel_config.a1}}</el-link><br/> -->
              <!-- <el-link>书籍名称 : {{ row.channel_config.a2 }}</el-link><br/> -->
               <!--<el-link type="warning">小米 : {{configFormat(row.config, 'a3')}}</el-link>
              <el-link type="danger">华为 : {{configFormat(row.config, 'a4')}}</el-link>
              <el-link>全量 :{{configFormat(row.config, 'a5')}}</el-link> -->
              <el-link>拉起间隔 : {{configFormat(row.channel_config, 'a6')}}</el-link><br/>
              <el-link>推广回传概率 : {{configFormat(row.channel_config, 'a9')}}</el-link><br/>
              <!-- <el-link>口令 : {{configFormat(row.config, 'a7')}}</el-link><br/> -->
              <!-- <el-link>组合链接 : {{configFormat(row.config, 'a14')}}</el-link> -->
              <el-link>回传触发事件: {{configFormat(row.channel_config, 'a8')}}</el-link> <br/>
              <div v-if="row.pkg != 'com.jianyue.photo'">
                <div>书籍id： {{ row.channel_config.a1 }}</div>
                <div>书籍名称： {{ row.channel_config.a2 }}</div>
              </div>
              <div v-else>
                <div>作者： {{ row.channel_config.a1? author_list[row.channel_config.a1]: '' }}</div>
                <div>分类：{{ row.channel_config.a2? classify[row.channel_config.a2]: ''}} </div>
              </div>
            <!-- <el-link type="primary">oppo包 : {{configFormat(row.config, 'a10')}}</el-link>
              <el-link type="success">vivo包 : {{configFormat(row.config, 'a11')}}</el-link>
              <el-link type="warning">小米包 : {{configFormat(row.config, 'a12')}}</el-link>
              <el-link type="danger">华为包 : {{configFormat(row.config, 'a13')}}</el-link> -->
          </div>
        </template>
      </el-table-column>

      <el-table-column
        label="操作"
        align="center"
        min-width="100"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="{row}">
          <el-link @click="showldtData(row)">查看落地页</el-link>
          <el-link type="primary" @click="handleUpdate(row)">编辑渠道</el-link>
          <el-link type="danger" @click="handleLogin(row)">登录渠道</el-link>
          <el-link v-if="row.status === '1'" type="warning" @click="pullSetting(row)">修改配置</el-link>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      class="pageShow"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />

    <!-- 添加渠道 -->
    <el-dialog
      :title="textMap[dialogStatus]"
      :visible.sync="dialogFormVisible"
      :width="dialogWidth"
    >
      <el-form
        ref="dataForm"
        :rules="rules"
        :model="temp"
        label-width="120px"
        class="fullwidth"
      >
        <el-form-item label="账号" prop="username">
          <el-input
            v-model="temp.username"
            placeholder="请输入账号"
            :disabled="dialogStatus==='update'"
          />
        </el-form-item>
        <el-tooltip v-model="capsTooltip" content="Caps lock is On" placement="right" manual>
          <el-form-item label="密码">
            <el-input
              :key="passwordType"
              ref="password"
              v-model="temp.password"
              :type="passwordType"
              placeholder="请输入密码"
              name="password"
              tabindex="2"
              autocomplete="on"
              @blur="capsTooltip = false"
            />
            <!-- <span class="show-pwd" @click="showPwd">
              <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
            </span> -->
          </el-form-item>
        </el-tooltip>
        <el-form-item label="hap包" prop="pkg">
           <el-select
            v-model="temp.pkg"
            style="width: 100%"
            class="filter-item"
            filterable
            @change="changePkg()"
          >
            <el-option
              v-for="(v, k) in optionPackageName"
              :key="k"
              :label="v"
              :value="k"
            />
          </el-select>
        </el-form-item>
        <el-form-item v-if="temp.pkg != 'com.jianyue.photo'" label="书籍id" prop="bookid" >
  
            <el-input v-model="temp.bookid" placeholder="请输入书籍/图片id" style="width: 150px;" :disabled="true"/>
            <el-link type="primary" style="margin-left:50px" @click="bookVisible=true">选择书籍</el-link>
            <br/>
            <span v-if="this.temp.bookname "> 书籍名称 ： {{ this.temp.bookname }}</span>
    
        </el-form-item>
        <el-form-item v-if="temp.pkg == 'com.jianyue.photo'" label="作者">

            <el-select v-model="temp.bookid" placeholder="请选择作者" style="width: 100%" class="filter-item" filterable @change="handleChange">
                <el-option
                  v-for="(v, key) in author_list"
                  :key="key"
                  :label="v"
                  :value="key"
                >
                </el-option>
            </el-select>
        </el-form-item>

        <el-form-item  v-if="temp.pkg == 'com.jianyue.photo'" label="分类">
          <el-select v-model="temp.bookname" placeholder="请选择分类" style="width: 100%" class="filter-item" filterable  @change="handleChange" >
                <el-option
                  v-for="(v, key) in classify"
                  :key="key"
                  :label="v"
                  :value="key"
                >
                </el-option>
            </el-select>
          </el-form-item>
         <!-- <el-form-item label="IP单价">
          <el-input v-model="temp.price_ip" placeholder="请输入IP单价" />
        </el-form-item> -->

        <!-- <el-form-item label="统计代码">
          <el-input type="textarea" v-model="temp.remark" placeholder="请输入统计代码" />
        </el-form-item> -->
         <!-- <el-form-item label="全量统计代码">
          <el-input type="textarea" v-model="temp.replace_js" placeholder="全量统计代码（统计所有的量，对比统计渠道说少ip）" />
        </el-form-item> -->
         <!-- <el-form-item label="结算方式">
          <el-input v-model="temp.shield" placeholder="请输入结算方式" />
        </el-form-item> -->
        
        <el-form-item label="推广渠道" prop="tg">
          <el-select
            v-model="temp.tg"
            style="width: 150px"
            class="filter-item"
            size="small"
          >
            <el-option v-for="(v, k) in tg_option" :key="k" :label="v" :value="k" />
          </el-select>
        </el-form-item>

        <el-form-item v-if="temp.tg == 'oppo'" label="推广渠道" prop="show">
          <el-select
            v-model="temp.show"
            style="width: 150px"
            class="filter-item"
            size="small"
          >
            <el-option v-for="(v, k) in oppo_account" :key="k" :label="v" :value="k" />
          </el-select>
        </el-form-item>

        <el-form-item label="推广模版"  prop="landing_page_id">
            <el-image 
                v-for="(v, k) in langind_option" 
                :key="k"
                style="width: 100px; height: 192px; margin-right: 10px;"
                :class="temp.landing_page_id.indexOf(k) > -1 ? 'order_1': 'order_2'"
                :src="v.img_url"
                fit="fill"
                @click="clicktemplate(k)"
                >
              </el-image>
        </el-form-item>

        <div style="text-align: right">
          <el-button @click="dialogFormVisible = false" plain size="small">取消</el-button>
          <el-button
           plain size="small"
            type="primary"
            :loading='addloading'
            @click="dialogStatus==='create'?addProxyOrChannel():editUserInfo()"
          >确定</el-button>
        </div>
      </el-form>
    </el-dialog>
    
      <el-dialog
      title="落地页"
      :visible.sync="ldyVisible"
      width="80%">
      <div>
        <el-table
        :data="ldtData"
        style="width: 100%">
        <el-table-column label="落地页链接" min-width="200" align="center">
          <template slot-scope="{row}">
            <div v-html="get_luodiye(langind_list, row)"></div>
          </template>
        </el-table-column>
        <el-table-column label="落地页图片" min-width="100" align="center">
          <template slot-scope="{row}">
            <el-image 
              v-if="langind_list[row.id]"
              style="width: 50px; height: 100px"
              :src="langind_list[row.id].img_url" 
              :preview-src-list="[langind_list[row.id].img_url]">
            </el-image>
          </template>
        </el-table-column>
      </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="ldyVisible = false">关闭</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="书籍搜索"
      :visible.sync="bookVisible"
      width="80%">
      <div>
        <div class="filter-container">
        <el-input type="input" v-model="bookQuery.bookid" placeholder="书籍id搜索" style="width: 220px;"
        class="filter-item" />
        <el-input type="input" v-model="bookQuery.name" placeholder="书籍名称搜索" style="width: 220px;"
        class="filter-item"/>
       
        <a-button type="primary" size="large" @click="bookhandleFilter">
          搜索
        </a-button>
        <a-button type="default" size="large" @click="bookhandleFilter">
          重置
        </a-button>
      </div>
  
      <el-table
        :key="tableKey"
        v-loading="listLoading"
        :data="booklist"
        fit
        highlight-current-row
        style="width: 100%"
      >
      <el-table-column key="1235" type="expand">
          <template slot-scope="props">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item label="封面:" key="11">
                <el-image
                  style="width: 90px; height: 120px"
                  :src="props.row.BookPic"
                  fit="fit">
                </el-image>
              </el-form-item>
              <el-form-item label="介绍:" key="12">
                <span>{{ props.row.intro}}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>

        <el-table-column
          key="1"
          label="书籍id"
          align="center"
          prop="book_id"
          min-width="50"
        >
        </el-table-column>
        <el-table-column
          key="2"
          label="书籍名称"
          align="center"
          prop="name"
          min-width="50"
        >
        </el-table-column>
        <el-table-column
          key="3"
          label="作者"
          align="center"
          prop="author"
          min-width="50"
        >
        </el-table-column>
        <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="bookSelect(scope.row)">选择此书</el-button>
      </template>
    </el-table-column>
      </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="bookVisible = false">关闭</el-button>
      </span>
    </el-dialog>

    <el-dialog :title="channel_name + '拉起配制'" :visible.sync="pull_setting_dialog" label-position="top"  width="600px">
        <div v-loading="channel_loading">
            <el-form :model="form">

          <!-- <el-form-item label="拉起间隔(小时):">
            <el-input type="number" v-model.number="form.a6" autocomplete="off" style="width: 100px"></el-input>
          </el-form-item> -->

          <el-form-item label="回传率(万分比):">
                <el-input type="number" v-model.number="form.a9" autocomplete="off" style="width: 100px"></el-input>
            </el-form-item>
          <!-- <el-form-item label="回传触发事件:">
      
              <el-select
                  v-model="form.a8"
                  style="width: 150px"
                  class="filter-item"
                  filterable
                >
                  <el-option label="未选择" value="" />
                  <el-option label="uv" value="uv" />
                  <el-option label="点击" value="ex" />
              </el-select>
              <span> * 未选择默认uv是回传事件</span>
          </el-form-item> -->

        </el-form>
        </div>
        
        <div slot="footer" style="text-align:left" class="dialog-footer">
          <el-button @click="pull_setting_dialog = false">取 消</el-button>
          <el-button type="primary" @click="subChannelConfig()">确 定</el-button>
        </div>
      </el-dialog>

      <el-dialog
      title="图片搜索"
      :visible.sync="tupianVisible"
      width="80%">
      <div class="filter-container">
        <el-input type="input" v-model="tupianQuery.pic_id" placeholder="图片id搜索" style="width: 220px;"></el-input>
        <el-select v-model="tupianQuery.classify_id" filterable placeholder="请选择分类">
            <el-option
            v-for="(v, key) in classify"
            :key="key"
            :label="v"
            :value="key"
            >
            </el-option>
        </el-select>

        <el-select v-model="tupianQuery.author_id" filterable placeholder="请选择作者">
            <el-option
            v-for="(v, key) in author_list"
            :key="key"
            :label="v"
            :value="key"
            >
            </el-option>
        </el-select>

        <a-button type="primary" size="large" @click="tupianhandleFilter">
          搜索
        </a-button>
        <a-button type="default" size="large" @click="tupianhandleCancel">
          重置
        </a-button>
  
      </div>
  
      <el-table
        :key="tableKey"
        v-loading="listLoading"
        :data="tupianlist"
        border
        fit
        highlight-current-row
        style="width: 100%"
      >
        <el-table-column
          key="2"
          label="图片"
          align="center"
          prop=""
          min-width="50"
        >
        <template slot-scope="{row}">
          <el-link v-if="is_video(row.img_path.img_thumbnail)" @click="show_video(row.img_path.img_thumbnail)" type="success">查看视频</el-link>
          <el-image v-else
              style="width: 100px; height: 100px"
              :src="row.img_path.img_thumbnail ? row.img_path.img_thumbnail: '1'" 
              :preview-src-list="[row.img_path.img_thumbnail]">
          </el-image>
        </template>
        </el-table-column>
        <el-table-column
          key="1"
          label="作者"
          align="center"
          prop="author_id"
          min-width="50"
        >
        <template slot-scope="{row}">
            <span>{{ author_list[row.author_id] }}</span>
        </template>
        </el-table-column>
        
        <el-table-column
          key="3"
          label="图片id"
          align="center"
          prop="pic_id"
          min-width="50"
        >
        </el-table-column>
        <el-table-column
          key="5"
          label="类别"
          align="center"
          prop="classify_id"
          min-width="50"
        >
            <template slot-scope="{row}">
                <span>{{ classify[row.classify_id] }}</span>
            </template>
        </el-table-column>

        <el-table-column
          key="6"
          label="下载次数"
          align="center"
          prop="download_sum"
          min-width="50"
        >
        <template slot-scope="{row}">
            <span>{{ row.download_sum}}</span>
        </template>
        </el-table-column>
        <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="tupianSelect(scope.row)">选择此图片</el-button>
        </template>
      </el-table-column>

  
      </el-table>

      <pagination
        v-show="tupiantotal > 0"
        :total="tupiantotal"
        class="pageShow"
        :page.sync="tupianQuery.page"
        :page_size.sync="tupianQuery.page_size"
        @pagination="getList"
      />
      
      <span slot="footer" class="dialog-footer">
        <el-button @click="tupianVisible = false">关闭</el-button>
      </span>
    </el-dialog>

    <VideoPlayer :url="video_url" :show="video_show" @clear="video_url = '', video_show=false"></VideoPlayer>
  </div>
</template>

<script>
import {
  getChannelList1,
  addProxyOrChannel,
  editUserInfo,
  quickLogin,
  getLangingPage,
  getChannelConfig,
  setChannelConfig
} from "@/api/admin/admin";
import {
   getPhotoCatygory,
    getAuthor,
    getPhoto,
    BookSearch
  } from "@/api/admin/book";
import {
  getPkgList
} from "@/api/adv_admin/config";
import waves from "@/directive/waves"; // waves directive
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
import { Message } from "element-ui";
import { setToken, setUser, setType } from "@/utils/auth";
import {get_hap, get_jiance, get_luodiye} from '@/utils/index'
import {is_video, oppo_account} from '@/utils/index'
import VideoPlayer from "@/components/VideoPlayer"
export default {
  name: "Control",
  components: { Pagination, VideoPlayer},
  directives: { waves },
  data() {
    return {
      oppo_account,
      video_show: false,
      video_url: '',
      is_video,
      get_hap,
      get_jiance,
      get_luodiye,
      ldtData: [],
      ldyVisible: false,
      bookVisible: false,
      booklist: [],
      optionPackageName: [],
      user: this.$store.state.user.name,
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      acc: "",
      pwd: "",
      pri: "",
      listQuery: {
        page: 1,
        limit: 20,
        proxy: "",
        status: "",
      },
      langind_list : {},
      langind_option : {},
      tg_option: {},
      temp: {
        username: "",
        password: "",
        price: 1.0,
        price_ip: "",
        ladder_price: "1",
        virtual_price: "1",
        remark: "",
        replace_js: "",
        shield:"",
        tg: "",
        show: '', // 其他字段，暂时用于给oppo推广渠道存账户
        landing_page_id:[] ,
        pkg: '',
        bookname:'',
        bookid:''
      },
      bookQuery: {
          page: 1,
          page_size: 50,
          bookid: '',
          name: "",
        },
      passwordType: "password",
      capsTooltip: false,
      dialogFormVisible: false,
      dialogStatus: "",
      dialogWidth: 0,
      textMap: {
        update: "修改渠道",
        create: "新增渠道",
      },
      rules: {
        username: [
          { required: true, message: "账号是必需的", trigger: "blur" },
          {
            validator: (rule, value, callback) => {
              if (/^[a-zA-Z0-9\_]+$/.test(value) === false) {
                callback(new Error("账号只能包含英文，数字，下划线"));
              } else {
                callback();
              }
            },
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "密码是必需的", trigger: "blur" },
        ],
        price: [
          { required: true, message: "单价是必需的", trigger: "blur" },
          {
            validator: (rule, value, callback) => {
              if (/^[0-9][0-9]*(\.[0-9]{1,2})?$/.test(value) === false) {
                callback(new Error("请输入一个数字，只支持两位小数"));
              } else {
                callback();
              }
            },
            trigger: "blur",
          },
        ],
        pkg: [
          { required: true, message: "请选择hap 包", trigger: "blur" },
        ],
        tg: [
          { required: true, message: "请选择推广渠道", trigger: "blur" },
        ],
        landing_page_id: [
          { required: true, message: "请选择模版", trigger: "blur" },
        ],
        show:[
        { required: true, message: "请选择账号", trigger: "blur" },
        ]
      },
      addloading: false,
      pull_setting_dialog:false,
      channel_loading: false,
      form: {},
      channel_name: '',
      is_fz: false,
      tupianQuery:{
        page: 1,
        page_size: 20,
        author_id: "",
        classify_id: "",
        pic_id: '',
        status: "",
      },
      tupianVisible: false,
      classify:{},
      author_list: {},
      tupianlist: [],
      tupiantotal: 0
    };
  },
  created() {
    this.getPkgs();
    // this.getClassify()
    // this.getAuthor()
    this.getLangingPages();
    this.getList();
    this.setDialogWidth();
  },
  mounted() {
    window.onresize = () => {
      return (() => {
        this.setDialogWidth();
      })();
    };
  },
  methods: {
    getPkgs(){
        getPkgList({data_type: '1'}).then((res)=>{
          this.optionPackageName = res.DATA.list
        })
      },
    show_video(url){
        this.video_show = true
        this.video_url = url
      },
    tupianhandleCancel(){
      this.tupianQuery = {
        page: 1,
        page_size: 20,
        author_id: "",
        classify_id: "",
        pic_id: '',
        status: "",
      }
      this.tupianlist = []
  },
  tupianhandleFilter() {
    this.listLoading = true;
    getPhoto(this.tupianQuery).then(res => {
      this.listLoading = false;

      if (res.code == 200){
        this.tupianlist = res.data.pic_list
        this.tupiantotal = res.data.total
      }else{
        Message({
            message: res.message,
            type: "error",
            duration: 2000,
          });
      }
    })
        
  },
  // getAuthor(){
  //     getAuthor({menu: '1'}).then(res => {
  //           if(res.code == 200){
  //             this.author_list = res.data.list
  //           }
  //       })
  //   },
  // getClassify(){
  //   getPhotoCatygory().then(res => {
  //       if(res.code == 200){
  //           this.classify = res.data.category;
  //       }
  //   })
  // },
  classifyName(classify_id){
    for(let item of this.classify){
        if (classify_id == item.category_id){
            return item.name
        }
    }

  },
    subChannelConfig(){
      setChannelConfig({channel: this.channel_name, config: JSON.stringify(this.form)}).then(res => {
        if (res.STATUS == 200){
          this.$message.success('修改成功')
          this.pull_setting_dialog = false
          this.getList();
        }else{
          this.$message.error(res.DEC)
        }
        
      })
    },
    pullSetting(v) {
      this.pull_setting_dialog = true
      this.channel_loading = true
      getChannelConfig({'channel': v.username}).then(res => {
        if (res.STATUS == 200) {
          this.form = JSON.parse(res.DATA.config)
          this.channel_name = v.username
          this.is_fz = res.DATA.is_fuzhou
        } else{
          this.$message.error(res.DEC)
          this.pull_setting_dialog = false
        }
        this.channel_loading = false
      })
    },
    configFormat(config,key){
      let c = config
      switch(key){
        case 'a1':
          return c[key]? "开":"关"
        case 'a2':
          return c[key]? "开":"关"
        case 'a3':
          return c[key]? "开":"关"
        case 'a4':
          return c[key]? "开":"关"
        case 'a5':
          return c[key]? "开":"关"
        case 'a7':
          return c[key]? "开":"关"
        case 'a8':
          if(c[key]){
            if(c[key] == 'ex'){
              return '点击'
            }
            return c[key]
          }
          return c[key]
        case 'a10':
          return this.pp[c[key]]
        case 'a11':
          return this.pp[c[key]]
        case 'a12':
          return this.pp[c[key]]
        case 'a13':
          return this.pp[c[key]]
        default:
          return c[key]
      }
    },
    showldtData(row){
      this.ldyVisible = true
      this.ldtData = []
      for(let k in row.landing_page_id){
        this.ldtData.push({
          'id': row.landing_page_id[k],
          'username': row.username,
          'tg': row.tg,
          'channel_config': row.channel_config,
          'show': row.show
        })
      }
      // console.log(this.ldtData)
    },
    changePkg(set){
      this.langind_option = {}
      for(let key in this.langind_list){
        
        if (this.langind_list[key]['pkg'] == this.temp.pkg){
          this.langind_option[key] = this.langind_list[key]
        }
      }
      if(!set){
        // console.log(1111,set)
        this.temp.landing_page_id = []
        this.temp.bookid = '',
        this.temp.bookname = ''
      }
      
    },
    getLangingPages(){
      getLangingPage({'tg': '1'}).then(res => {
        if (res.STATUS == 200){
          this.langind_list = res.DATA.landing_page;
          this.tg_option = res.DATA.tg
        }
      })
    },
    setDialogWidth() {
      const val = document.body.clientWidth;
      const def = 800; // 默认宽度
      if (val < def) {
        this.dialogWidth = "100%";
      } else {
        this.dialogWidth = def + "px";
      }
    },
    //添加渠道
    addProxyOrChannel() {
      if (
        this.temp.username === "" ||
        /^[a-zA-Z0-9\_]+$/.test(this.temp.username) === false
      ) {
        Message({
          message: "账号只能包含英文，数字，下划线",
          type: "error",
          duration: 2000,
        });
        return;
      }
      if (this.temp.password === "") {
        Message({
          message: "密码必须填写",
          type: "error",
          duration: 2000,
        });
        return;
      }
      if (
        this.temp.price === "" ||
        /^[0-9][0-9]*(\.[0-9]{1,2})?$/.test(this.temp.price) === false
      ) {
        Message({
          message: "UV单价必须填写且最多支持两位小数",
          type: "error",
          duration: 2000,
        });
        return;
      }
      if (
        this.temp.price_ip === "" ||
        /^[0-9][0-9]*(\.[0-9]{1,2})?$/.test(this.temp.price_ip) === false
      ) {
        Message({
          message: "IP单价必须填写且最多支持两位小数",
          type: "error",
          duration: 2000,
        });
        return;
      }
      this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.addloading = true
            this.temp.landing_page_id = JSON.stringify(this.temp.landing_page_id)
            addProxyOrChannel(this.temp).then((response) => {
              if (response.STATUS === 200) {
                this.handleFilter();
                this.dialogFormVisible = false;
                Message({
                  message: response.DEC || "添加成功",
                  type: "success",
                  duration: 2000,
                });
              } else {
                Message({
                  message: response.DEC || "添加失败",
                  type: "error",
                  duration: 2000,
                });
              }
              this.addloading = false
            });

          }
      })
      
    },
   
    getList() {
      this.listLoading = true;
      getChannelList1(this.listQuery).then((response) => {
        this.list = response.DATA.list;
        this.total = response.DATA.total;
        this.listLoading = false;
      });
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
    handleCancel() {
      this.listQuery.page = 1;
      this.listQuery.proxy = "";
      this.getList();
    },
    resetTemp() {
      this.temp = {
        id: undefined,
        username: "",
        password: "",
        price: 1.0,
        price_ip: 1.0,
        virtual_price: "1",
        ladder_price: "1",
        remark: "",
        role_id: 2,
        replace_js: "",
        // shield:"",
        pkg: '',
        tg: "",
        landing_page_id:[]
      };
    },
    handleCreate() {
      this.resetTemp();
      this.temp.pkg = ''
      this.dialogStatus = "create";
      this.dialogFormVisible = true;
      this.changePkg()
    },
    showPwd() {
      if (this.passwordType === "password") {
        this.passwordType = "";
      } else {
        this.passwordType = "password";
      }
      this.$nextTick(() => {
        this.$refs.password.focus();
      });
    },

    handleUpdate(row) {
      this.resetTemp();
      this.temp.id = row.id;
      this.temp.username = row.username;
      this.temp.price = row.price;
      this.temp.price_ip = row.price_ip;
      this.temp.virtual_price = row.virtual_price;
      this.temp.ladder_price = row.ladder_price;
      this.temp.remark = row.remark;
      this.temp.replace_js = row.replace_js
      // this.temp.shield = row.shield
      this.temp.tg = row.tg
      this.temp.pkg = row.pkg
      this.temp.landing_page_id = row.landing_page_id
      this.temp.bookid = row.channel_config.a1
      this.temp.bookname = row.channel_config.a2
      this.temp.show = row.show
      this.dialogStatus = "update";
      this.dialogFormVisible = true;
      this.changePkg(1)
    },
    //修改渠道状态
    changeProxyStatus(row) {
      this.temp.id = row.id;
      this.temp.username = row.username;
      this.temp.price = row.price;
      this.temp.price_ip = row.price_ip;
      this.temp.virtual_price = row.virtual_price;
      this.temp.ladder_price = row.ladder_price;
      this.temp.remark = row.remark;
      this.temp.status = row.status;
      this.temp.replace_js = row.replace_js
      // this.temp.shield = row.shield
      this.temp.ua = row.ua
      this.temp.pkg = row.pkg
      this.temp.landing_page_id = row.landing_page_id
      this.temp.bookid = row.channel_config.a1
      this.temp.bookname = row.channel_config.a2
      this.saveEdit()
    },
    //编辑渠道
    editUserInfo() {
      if (
        this.temp.price === "" ||
        /^[0-9][0-9]*(\.[0-9]{1,2})?$/.test(this.temp.price) === false
      ) {
        Message({
          message: "UV单价必须填写且最多支持两位小数",
          type: "error",
          duration: 2000,
        });
        return;
      }
      if (
        this.temp.price_ip === "" ||
        /^[0-9][0-9]*(\.[0-9]{1,2})?$/.test(this.temp.price_ip) === false
      ) {
        Message({
          message: "IP单价必须填写且最多支持两位小数",
          type: "error",
          duration: 2000,
        });
        return;
      }
      this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.saveEdit()
          }
      })
      
    },
    saveEdit(){
      this.addloading = true
      this.temp.landing_page_id = JSON.stringify(this.temp.landing_page_id)
            editUserInfo({ id: this.temp.id }, this.temp).then((response) => {
            if (response.STATUS === 200) {
              this.dialogFormVisible = false;
              this.getList();
              Message({
                message: response.DEC || "修改成功",
                type: "success",
                duration: 2000,
              });
            } else {
              Message({
                message: response.DEC || "修改失败",
                type: "error",
                duration: 2000,
              });
            }
            this.addloading = false
          });
    },
    clicktemplate(id){
      let index = this.temp.landing_page_id.indexOf(id)
      
      if (index == -1){
        this.temp.landing_page_id.push(id)
      }else{
        this.temp.landing_page_id.splice(index,1)
      }
      console.log(this.temp.landing_page_id, id, index)
    },
    //登录
    handleLogin(row) {
      quickLogin({ id: row.id }).then((response) => {
        if (response.STATUS === 200) {
          if (response.DATA.user_type == 2) {
            let domin1 = "Admin-Token-proxy.jianyue668.com";
            let domin2 = "user-proxy.jianyue668.com";
            let domin3 = "type-proxy.jianyue668.com";
            setToken(response.DATA.token, domin1);
            setUser(response.DATA, domin2);
            setType("daili", domin3);
            window.open("http://proxy.jianyue668.com/", "_blank");
          } else if (response.DATA.user_type == 3) {
            let domin1 = "Admin-Token-qudao.jianyue668.com";
            let domin2 = "user-qudao.jianyue668.com";
            let domin3 = "type-qudao.jianyue668.com";
            setToken(response.DATA.token, domin1);
            setUser(response.DATA, domin2);
            setType("qudao", domin3);

            window.open("http://qudao.jianyue668.com", "_blank");
          }
        } else {
          Message({
            message: response.msg || "获取token失败",
            type: "error",
            duration: 2000,
          });
        }
      });
    },
    bookhandleFilter() {
      this.bookQuery.page = 1;
      this.getbookList();
    },
    getbookList() {
        this.listLoading = true;
        BookSearch(this.bookQuery).then(res => {
          this.listLoading = false;

          if (res.code == 200){
            this.booklist = res.data.list
          }else{
            Message({
                message: res.message,
                type: "error",
                duration: 2000,
              });
          }
          // console.log(res)
        })
    },
    bookSelect(row){
      this.temp.bookid = row.book_id;
      this.temp.bookname = row.name
      this.bookVisible = false
      this.booklist= []
    },
    tupianSelect(row){
      this.temp.bookid = row.pic_id;
      this.temp.bookname = row.img_path.img_thumbnail
      this.tupianVisible = false
      this.tupianlist= []
    },
    handleChange(val) {
      this.$forceUpdate() // 强制刷新
      // if (val) {
      //     this.$set(this.UrgeTaskListPage, this.UrgeTaskListPage.accountPeriod, val)
      // } else {
      //     this.$set(this.UrgeTaskListPage, this.UrgeTaskListPage.accountPeriod, '')
      // }
    }
  },
  
};
</script>

<style lang="scss" scoped>

.demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 90%;
  }
.show-pwd {
  position: absolute;
  right: 10px;
  top: 0;
  font-size: 16px;
  color: #ccc;
  cursor: pointer;
  user-select: none;
}
.push {
  display: inline-block;
  width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
  margin-left: 5px;
}
.pageHidden {
  display: none;
}
.btn {
  margin-left: 0;
}
.fullwidth {
  width: 450px;
  margin-left: 50px;
}
@media (max-width: 550px) {
  .pageShow {
    display: none;
  }
  .pageHidden {
    display: block;
  }
  .fullwidth {
    width: 100%;
    margin-left: 0;
  }
}
.order_1{
  padding: 2px;
  border-radius: 4px;
  border: 2px solid #409EFF;
}
.order_2{
  border-radius: 4px;
  border: 1px solid #cccccc;
}
.demo-table-expand .el-form-item .el-form-item__content div{
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal;
    word-break: break-all
  }
</style>
